package com.gdyx.app.web.svc.impl;

import com.gdyx.app.web.dao.MpsFunOptDao;
import com.gdyx.app.web.dao.MpsRoleOptDao;
import com.gdyx.app.web.model.MpsFunOpt;
import com.gdyx.app.web.svc.MpsFunOptSvc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * Created by Y_Coffee on 2017/8/3.
 */
@Service
public class MpsFunOptSvcImpl implements MpsFunOptSvc {
    @Autowired
    MpsFunOptDao dao;
    @Autowired
    MpsRoleOptDao mpsRoleOptDao;

    @Override
    public void save(MpsFunOpt o) {
        o.setId(UUID.randomUUID().toString().toUpperCase().trim().replaceAll("-", ""));
        o.setFunId(o.getFunId());
        o.setCreateTime(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
        dao.save(o);
    }

    @Override
    public void saveOrUpdate(MpsFunOpt o) {
        dao.saveOrUpdate(o);
    }

    @Override
    public void delete(String id) {
        dao.delete(id);
    }

    @Transactional
    @Override
    public void deleteOptsAndRoleOpts(String id) {
        //删除角色操作关联表
        mpsRoleOptDao.deleteByOptId(id);
        //删除操作表
        this.delete(id);
    }

    @Override
    public void update(MpsFunOpt o) {
        o.setModifyTime(new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()));
        dao.update(o);
    }

    @Override
    public MpsFunOpt findMpsFunOptById(String id) {
        return dao.findMpsFunOptById(id);
    }

    @Override
    public int count(Map<String, Object> map) {
        return dao.count(map);
    }

    @Override
    public List<MpsFunOpt> findMpsFunOpts(Map<String, Object> map) {
        return dao.findMpsFunOpts(map);
    }
}
